﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using LinqObj;

/// <summary>
/// Summary description for PropertyListGenerator
/// </summary>


namespace ToolBoxPro
{
    public class PropertyListBuilder
    {
        private string artworkIcon = String.Format("<a href='#'><div class='artwork'></div></a> ", "", "Check-icon.png");
        private List<Property> propertyList;
        private IDictionary<int, string> vendorStatusLookups;

        /*
         * <table>
         * <thead> <th> </th> </thead>
         * <tbody>
         *  <tr>
         *      <td>
         *          <img src="campaign_status">
         *      </td>
         *      <td>
         *          <img src="allocated_status">
         *      </td>
         *      <td>
         *          <a>Property Address.......</a>
         *      </td>
         *      <td>
         *          create date
         *      </td>
         *  </tr>
         *  </tbody>
         *  <tfoot> <tr> </tr> </tfoot>
         * </table>
         */
        // Dictionary<int, string> dic = new Dictionary<int, string>();

        public PropertyListBuilder(IEnumerable<Property> _propertyList)
        {
            this.propertyList = (List<Property>)_propertyList;
            this.vendorStatusLookups = new Dictionary<int, string>();
            ToolboxDataContext context = new ToolboxDataContext();
            var _lookups = from _vendor_status in context.GetTable<Vendor_Status>()
                           select new { _key = _vendor_status.vendor_status_id, _value = _vendor_status.vendor_status1 };

            foreach (var _entry in _lookups)
            {
                this.vendorStatusLookups.Add(_entry._key, _entry._value);
            }
        }

        public Control BuildPropertyList()
        {

            HtmlGenericControl container = new HtmlGenericControl("div");
            container.Attributes["class"] = "property_list";

            HtmlGenericControl header = new HtmlGenericControl("h1");
            header.InnerText = "Manage the Campaigns";
            container.Controls.Add(header);

            HtmlGenericControl propertyTable = new HtmlGenericControl("table");
            propertyTable.Attributes["width"] = "800";
            container.Controls.Add(propertyTable);

            LiteralControl thead = new LiteralControl(@"<thead><tr>
                                        <th width ='20%'>Shoppring Cart</th>                                        
                                        <th>Status</th>
                                        <th>Property Detail</th>
                                        <th>Created</th>
                                        <th>Last Modified</th>
                                        <th>Vendor Status</th>
                                        </tr></thead>");

            propertyTable.Controls.Add(thead);

            foreach (Property p in propertyList)
            {
                //HtmlGenericControl gcTask = new HtmlGenericControl("div");
                //gcTask.Controls.Add(new LiteralControl(String.Format("<img src ='{0}' width='{1}'/>",
                //            icon, FormContract.THUMB_NAIL_SIZE_X)));

                HtmlGenericControl propertyEntry = new HtmlGenericControl("tr");
                propertyEntry.Attributes["id"] = p.property_id.ToString();
                propertyEntry.Attributes["class"] = "propertyEntry";
                propertyTable.Controls.Add(propertyEntry);

                HtmlGenericControl shoppingCarThumbNail = new HtmlGenericControl("td");
                shoppingCarThumbNail.Attributes["align"] = "center";
                shoppingCarThumbNail.InnerHtml = "<div class='" + p._AllocatedStatus + "'></div>";
                shoppingCarThumbNail.Attributes["height"] = "30";
                propertyEntry.Controls.Add(shoppingCarThumbNail);

                HtmlGenericControl tdStatus = new HtmlGenericControl("td");
                tdStatus.InnerText = p.PropertyStatusLabel;
                propertyEntry.Controls.Add(tdStatus);

                HtmlGenericControl propertyDetail = new HtmlGenericControl("td");
                propertyDetail.InnerHtml = "<p class='propertyInfo'><a href='#'>" + p.address1 + " " + p.address1 + " " + p.suburb + " " + p.state + "</a></p>";
                propertyEntry.Controls.Add(propertyDetail);

                //<th>Last Modified</th>
                //<th>Vendor Status</th>
                HtmlGenericControl tdCreatedDate = new HtmlGenericControl("td");
                tdCreatedDate.InnerText = FormContract.GetDateLabel(p.created_date);
                propertyEntry.Controls.Add(tdCreatedDate);

                HtmlGenericControl tdLastModified = new HtmlGenericControl("td");
                tdLastModified.InnerText = FormContract.GetDateLabel(p.last_modified_date);
                propertyEntry.Controls.Add(tdLastModified);

                HtmlGenericControl tdVendorStatus = new HtmlGenericControl("td");
                tdVendorStatus.InnerText = p.Vendor_Status1 == null ? "" : p.Vendor_Status1.vendor_status1;
                propertyEntry.Controls.Add(tdVendorStatus);
            }
            LiteralControl tfoot = new LiteralControl("<tfoot><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr></tfoot>");
            propertyTable.Controls.Add(tfoot);

            return container;
        }

        //protected void LinkButton1_Click(object sender, EventArgs e)
        //{
        //    LinkButton property = (LinkButton)sender;
        //    string t = property.ID;
        //    string id = t.Remove(0, "linkbt_".Length);
        //    HttpContext.Current.Response.Redirect("~/property.aspx?id=" + id, false);

        //}
    }

}